#!/bin/bash

USAGE="Usage: `basename $0` absolute-kernel-path cscope-database-path"
if [ "$1" = "" -o "$2" = "" ]; then
	echo $USAGE
	exit 1
fi
LNX="$1"
DB_PATH="$2"
if [ ! -e "${DB_PATH}" ]; then
	mkdir -v "${DB_PATH}"
fi
if [ ! -d "${DB_PATH}" ]; then
	echo "${DB_PATH} NOT a directory"
	exit 1
fi

cd / 	
find  $LNX \
	-path "$LNX/arch/*" ! -path "$LNX/arch/x86*" -prune -o \
	-path "$LNX/Documentation*" -prune -o \
	-path "$LNX/scripts*" -prune -o \
	-path "$LNX/drivers*" -prune -o \
	-path "$LNX/tools*" -prune -o \
	-path "$LNX/sound*" -prune -o \
	-path "$LNX/samples*" -prune -o \
	-path "$LNX/security*" -prune -o \
	-path "$LNX/crypto*" -prune -o \
	-path "$LNX/firmware*" -prune -o \
        -name "*.[chxsS]" -print >${DB_PATH}/cscope.files

cd ${DB_PATH}
cscope -b -q -k
